﻿using AMapPlugin;
using AMapPlugin.Dtos;
using IM.Easy.Core.Attributes;
using IM.Easy.Core.Extensions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace IM.Easy.Api.Controllers.System
{
    /// <summary>
    /// weather 控制器
    /// </summary>
    [Route("system/weather")]
    public class WeatherController : ControllerBase
    {
        private IAmapPlugin _amapPlugin;
        public WeatherController(IAmapPlugin amapPlugin)
        {
            _amapPlugin = amapPlugin;
        }

        /// <summary>
        /// 获取实时天气
        /// </summary>
        [Api(Name = "获取实况天气")]
        public async Task<WeatherInfo> GetLive()
        {
            var ip = HttpContext.GetClientUserIp();
            ip = "223.85.205.154";
            var clientIp = await _amapPlugin.GetIpInfo(ip);
            var weather = await _amapPlugin.GetWeather(clientIp.Adcode);
            weather.City = clientIp.City;
            weather.Province = clientIp.Province;
            return weather;
        }
    }
}
